<div class="register_menu">
  <form name = "registroUsuario" action="insertUser2.php" method="POST">
    <table align="center">
    <img src="images/top_low/logo2.jpg" alt="">
        <table border=0>
          <tr><td>Nombre</td>
            <td><input type="text" onkeypress="return noNumber(event)" onChange="verifNombre()" name="nombre" size="11" value="" ></td></tr>
          <tr><td id="nombreMsn" class="hid"></td><td class="exTel"></td></tr>
          <tr class="" id="rapellido"><td>Apellido</td><td><input type="text" onChange="verifApellido()" onkeypress="return noNumber(event)" name="apellido" size="11" value=""</td></tr>
          <tr><td id="apellido" class="hid"></td><td class="exTel"></td></tr>
          <tr><td>C&eacute;dula o RIF
                <select size="1" name="persona" onchange="swap()">
                  <option value="1">V</option>
                  <option value="0">J</option>
                </select>
              </td> <td>
                <input type="text" onkeypress="return verifCI(event)" onChange="verifCITam()" name="ci" size="11" value=""
              </td>
          </tr>
          <tr><td id="ci" class="hid"></td><td class="exTel"></td></tr>
          <tr><td>Tel&eacute;fono</td><td><input type="text" onkeypress="return verifTel(event)" onchange="verifTelTam()"name="telefono" size="11" value=""</td></tr>
          <tr><td id="telefono" class="hid">*Siga el ejemplo.</td><td class="exTel">Ej: 02125553344</td></tr>
          <tr><td>Correo electr&oacute;nico</td>
            <td><input type="text" onChange="verifCorreo()" name="correo" size="11" value=""</td></tr>
          <tr><td id="correo" class="hid">*Correo incorrecto.</td><td class="exTel">Ej: correo@ejemplo.com</td></tr>
          <tr><td>Contrase&ntilde;a</td><td><input type="password" name="contrasena" size="11" value=""</td></tr>
          <tr><td>Repita contrase&ntilde;a</td><td><input type="password" onChange="verifDistintas()" name="repetida" size="11" value=""</td></tr>
          <tr><td class="hid" id="clave">*Contraseñas distintas.</td><td></td></tr>
        </table>
        <center>
  <!--    <input type="button" value="registrar" name="registrar" onClick="javascript:comprueba();"> -->
          <img src="images/top_low/botones/registrarse.jpg"
               onclick="javascript:comprueba();"
               alt="Registrarse"/>
        </center>
        <input type="hidden" name="link" value="registroUsuario.php">
      <a href="" onClick="javascript:Show()" style="font-size: 9px ">No recuerdas tu contraseña?</a>
      <!--
      <form name="recuperar_Contraseña" action="recuperar_Contraseña.php" method="POST">

      </form>
      -->
    </table>
  </form>
</div>
<script language="javascript">
  function salio(){
    alert("Salio");
  }

  function noNumber(evt){
    var key = evt.charCode;
    if ((65 <= key && key <= 90) ||
         key ==241 ||
         key == 32 ||
         (97 <= key && key <= 122) ||
         key == 0){
      return true;
    }
    return false;
  }

  function swap(){
    if (document.registroUsuario.persona.value == 0){
      document.getElementById('rapellido').setAttribute('style','visibility: hidden');
      document.getElementById('apellido').setAttribute('style','visibility: hidden');
    }else{
      document.getElementById('rapellido').setAttribute('style','visibility: visible');
    }
  }

  function verifTel(evt){
    var key = evt.charCode;
    if (key == 0)
      return true;
    if (document.registroUsuario.telefono.value.length == 11)
      return false;
    if ((48 <= key && key <= 57))
      return true;
    return false;
  }

  function verifCITam(){
    if (document.registroUsuario.persona.value == 1 && document.registroUsuario.ci.value.length == 8)
      document.getElementById("ci").setAttribute('style','visibility: hidden');
    else if (document.registroUsuario.persona.value == 0 && document.registroUsuario.ci.value.length == 9)
      document.getElementById("ci").setAttribute('style','visibility: hidden');
    else
      document.getElementById("ci").setAttribute('style','visibility: visible');
  }

  function verifCI(evt){
    var key = evt.charCode;
    if (key == 0)
      return true;
    if (document.registroUsuario.persona.value == 1 && document.registroUsuario.ci.value.length == 8)
      return false;
    if (document.registroUsuario.persona.value == 0 && document.registroUsuario.ci.value.length == 9)
      return false;
    if (48 <= key && key <= 57){
      return true;
    }
    return false;
  }

  function verifDistintas(){
    if (document.registroUsuario.contrasena.value != document.registroUsuario.repetida.value)
      document.getElementById('clave').setAttribute('style','visibility: visible');
    else
      document.getElementById('clave').setAttribute('style','visibility: hidden');
  }

  function verifTelTam(){
    if (document.registroUsuario.telefono.value.length < 11){
      document.getElementById('telefono').innerHTML="*telefono incorrecto.";
      document.getElementById('telefono').setAttribute('style','visibility: visible');
    }
    else{
      document.getElementById('telefono').setAttribute('style','visibility: hidden');
    }
  }

  function verifCorreo(){
    var ExpRegCorreo = /^\w{3}([\.]*?[-]*?[_]*?\w+)*@\w{3}([\.-]?\w+)*(\.\w{2,4})+$/;
    if (!document.registroUsuario.correo.value.match(ExpRegCorreo)){
      document.getElementById('correo').setAttribute('style','visibility: visible');
      document.getElementById('correo').innerHTML="*correo incorrecto.";
    }
    else{
      document.getElementById('correo').setAttribute('style','visibility: hidden');
    }
  }

  function verifApellido(){
    var ExpRegNombre = /^[a-zA-Z]*([ ]{0,1}[a-zA-Z])*$/;
    var vacio =/^$/;
    if (!document.registroUsuario.apellido.value.match(ExpRegNombre) &&
        !document.registroUsuario.apellido.value.match(vacio) ){
      document.getElementById('apellido').setAttribute('style','visibility: visible');
    }
    else{
      document.getElementById('apellido').setAttribute('style','visibility: hidden');
    }
  }


  function verifNombre(){
    var ExpRegNombre = /^[a-zA-Z]*([ ]{0,1}[a-zA-Z])*$/;
    var vacio =/^$/;
    if (!document.registroUsuario.nombre.value.match(ExpRegNombre) &&
        !document.registroUsuario.nombre.value.match(vacio) ){
      document.getElementById('nombreMsn').setAttribute('style','visibility: visible');
    }
    else{
      document.getElementById('nombreMsn').setAttribute('style','visibility: hidden');
    }
  }

  function comprueba(){
    var ExpRegCorreo = /^\w{3}([\.]*?[-]*?[_]*?\w+)*@\w{3}([\.-]?\w+)*(\.\w{2,4})+$/;
    cor = true;
    if(document.forms.registroUsuario.contrasena.value != document.forms.registroUsuario.repetida.value){
      document.getElementById('clave').setAttribute('style','visibility: visible');
      document.getElementById('clave').innerHTML="*contraseñas distintas.";
      cor = false;
    }
    if (document.forms.registroUsuario.contrasena.value == ""){
      document.getElementById('clave').setAttribute('style','visibility: visible');
      document.getElementById('clave').innerHTML="*introducir una contraseña.";
      cor = false;
    }
    if (document.forms.registroUsuario.contrasena.value.length < 5){
      document.getElementById('clave').setAttribute('style','visibility: visible');
      document.getElementById('clave').innerHTML="*la contrasena debe tener al menos 5 caracteres.";
      cor = false;
    }
    if (document.forms.registroUsuario.correo.value == ""){
      document.getElementById('correo').innerHTML="*introducir un correo.";
      document.getElementById('correo').setAttribute('style','visibility: visible');
      cor = false;
    }
    else if (!document.forms.registroUsuario.correo.value.match(ExpRegCorreo)){
      document.getElementById('correo').innerHTML="*correo incorrecto.";
      document.getElementById('correo').setAttribute('style','visibility: visible');
      cor = false;
    }else{
      document.getElementById('correo').setAttribute('style','visibility: hidden');
    }
    if (document.forms.registroUsuario.nombre.value == ""){
      document.getElementById('nombreMsn').innerHTML="*introducir un nombre.";
      document.getElementById('nombreMsn').setAttribute('style','visibility: visible');
      cor = false;
    }else{
      document.getElementById('nombreMsn').setAttribute('style','visibility: hidden');
    }
    if (document.forms.registroUsuario.ci.value == ""){
      document.getElementById('ci').innerHTML="*introducir una CI o RIF.";
      document.getElementById('ci').setAttribute('style','visibility: visible');
      cor = false;
    }else{
      document.getElementById('ci').setAttribute('style','visibility: hidden');
    }
    if (document.registroUsuario.persona.value == 1){
      if (document.forms.registroUsuario.apellido.value == ""){
        document.getElementById('apellido').innerHTML="*introducir un apellido.";
        document.getElementById('apellido').setAttribute('style','visibility: visible');
        cor = false;
      }else{
        document.getElementById('apellido').setAttribute('style','visibility: hidden');
      }
    }
    if (document.registroUsuario.ci.value.length <= 6){
      document.getElementById('ci').innerHTML="*cedula invalida.";
      document.getElementById('ci').setAttribute('style','visibility: visible');
      cor = false;
    }
    if (document.forms.registroUsuario.telefono.value.length != 11){
      document.getElementById('telefono').innerHTML="*introducir telefono valido.";
      document.getElementById('telefono').setAttribute('style','visibility: visible');
      cor = false;
    }
    else{
      find = false;
      cod = document.registroUsuario.telefono.value.substring(0,4);
      lcod = new Array("0414","0412","0416","0424","0426","0212","0248","0281","0283","0282","0285","0292","0240","0247","0277","0278","0243","0244","0246","0273","0278","0284","0285","0286","0288","0289","0241","0242","0243","0245","0249","0258","0287","0259","0268","0269","0279","0235","0238","0246","0247","0251","0252","0253","0271","0274","0275","0234","0239","0291","0292","0287","0295","0255","0256","0257","0272","0293","0294","0275","0276","0277","0271","0272","0253","0254","0261","0262","0263","0264","0265","0266","0271");
      for(i = 0 ; i <lcod.length && !find;i++){
        if (lcod[i] == cod){
          find = true;
        }
      }
      if (!find){
        document.getElementById('telefono').setAttribute('style','visibility: visible');
        document.getElementById('telefono').innerHTML="*codigo de area invalido.";
        cor = false;
      }
    }
    if (cor)
      document.registroUsuario.submit();
  }
</script>
